#include "StdAfx.h"
#include "cprintskillung.h"
#include "CharplanDoc.h"
#include "Charplan.h"
#include "CDialogPrinterOptions.h"

#include "dep/Printlib/CPage.h"

using namespace std;


CPrintSkillung::CPrintSkillung(void)
{
	mpc_options = NULL;
}

CPrintSkillung::CPrintSkillung(CCharplanDoc* doc) : CPrintBase(doc)
{
	mpc_options = NULL;
}

CPrintSkillung::~CPrintSkillung(void)
{
	if (mpc_options)	delete (mpc_options);
}


double CPrintSkillung::PrintTab(CPage* pPage, CPrintRegion*reg, double row, double col1, double col2, LPCTSTR t1, LPCTSTR t2)
{
	double res = row;
	if (reg != NULL)
	{
		res =	pPage->Print(reg,row, col1,TEXT_NORMAL|TEXT_SINGLELINE,9,t1);
				pPage->Print(reg,row, col2,TEXT_NORMAL|TEXT_SINGLELINE,9,t2);
	}
	else
	{
		res =	pPage->Print(row, col1,TEXT_NORMAL|TEXT_SINGLELINE,9,t1);
				pPage->Print(row, col2,TEXT_NORMAL|TEXT_SINGLELINE,9,t2);
	}

	return res;
}

double CPrintSkillung::PrintTab(CPage* pPage, CPrintRegion*reg, double row, double col1, double col2, int ptsize, LPCTSTR t1, LPCTSTR t2)
{
	double res = row;
	if (reg != NULL)
	{
		res =	pPage->Print(reg,row, col1,TEXT_NORMAL|TEXT_SINGLELINE,ptsize,t1);
				pPage->Print(reg,row, col2,TEXT_NORMAL|TEXT_SINGLELINE,ptsize,t2);
	}
	else
	{
		res =	pPage->Print(row, col1,TEXT_NORMAL|TEXT_SINGLELINE,ptsize,t1);
				pPage->Print(row, col2,TEXT_NORMAL|TEXT_SINGLELINE,ptsize,t2);
	}

	return res;
}


void	CPrintSkillung::GetAllSkillNames(CStringArray& result)
{
	result.RemoveAll();

	CStringArray result_lines;

	gdbinterface.GetListOfStyleLines(result_lines);
	result.Append(result_lines);
	gdbinterface.GetListOfSpellLines(result_lines);
	result.Append(result_lines);
}


int	CPrintSkillung::GetSkillLevel(CString name, float level)
{
	float level_backup  = mpc_doc->GetLevel();

	if (mpc_doc->IsCarrerMode())		mpc_doc->SetLevel(level);

	int res = mpc_doc->GetSpecLevel(name);

	if (mpc_doc->IsCarrerMode())		mpc_doc->SetLevel(level_backup);

	return res;
}



void	CPrintSkillung::GetListOfStyles(CStringArray& spec,    IntArray& specline, IntArray& indent, CStringArray& name, IntArray& level, int& nof_specs)
{

	// Maik Jurkait [29.12.2004]
	//===========================================
	// check options
	//===========================================
	ASSERT(mpc_options);
	if (!mpc_options->ms_options.mb_styles) return;
	bool all = mpc_options->ms_options.mb_all_styles;


	// Maik Jurkait [29.12.2004]
	//===========================================
	// Get style-lines
	//===========================================
	CStringArray lines;
	CStringArray snames;
	IntArray	 slevel;
	IntArray	 sids;

	gdbinterface.GetListOfStyleLines(lines);
	nof_specs = (int)lines.GetCount();



	for (int t=0;t<lines.GetCount();t++)
	{
		int currentline = -1;
		gdbinterface.SelectStyleLine(lines[t]);
		gdbinterface.GetListOfStyles(&snames, &slevel, &sids);

		for (int t2=0;t2<snames.GetCount();t2++)
		{
			if (!all && slevel[t2] > mpc_doc->GetSpecLevel(lines[t])) continue;

			if (currentline == -1) currentline = (int)spec.Add(lines[t]);

			gdbinterface.SelectStyleID(sids[t2]);
			CString strPreStyle = gdbinterface.GetStylePreStyle();

			
			if (!strPreStyle.IsEmpty() && mpc_options->ms_options.me_style_sort == ESTYLE_SORT_LINEandPRESTYLE)
			{
				int insertpos;
				for (insertpos=0; insertpos < name.GetCount();insertpos++)
				{
					if (name[insertpos] == strPreStyle && specline[insertpos] == currentline)
						break;
				}

				specline.InsertAt(insertpos+1,currentline);
				indent.InsertAt(insertpos+1, indent[insertpos]+1);
				name.InsertAt(insertpos+1,snames[t2]);
				level.InsertAt(insertpos+1,slevel[t2]);
			}
			else
			{
				specline.Add(currentline);
				indent.Add(0); 
				name.Add(snames[t2]);
				level.Add(slevel[t2]);
			}
		}
	}


	// Maik Jurkait [30.12.2004]
	//===========================================
	// SORT
	//===========================================

	// ESTYLE_SORT_LINEandPRESTYLE	handled in fill list loop
	// ESTYLE_SORT_LINEandLEVEL		don't need to be sorted; thats standard

	// ESTYLE_SORT_PERQUISITE resort all
	if (mpc_options->ms_options.me_style_sort == ESTYLE_SORT_PERQUISITE)
	{
		for (int t=0;t<name.GetCount()-1;t++)
			for (int t2=t+1;t2<name.GetCount();t2++)
			{
				gdbinterface.SelectStyleLine(lines[specline[t]]);
				gdbinterface.SelectStyle(name[t]);
				int pre1 = gdbinterface.GetStylePrePos();
				gdbinterface.SelectStyleLine(lines[specline[t2]]);
				gdbinterface.SelectStyle(name[t2]);
				int pre2 = gdbinterface.GetStylePrePos();

				if (pre1<pre2)
				{
					CString n = name[t];	name[t] = name[t2];		name[t2] = n;
					int l = level[t];		level[t] = level[t2];	level[t2] = l;
					l = indent[t];			indent[t] = indent[t2];	indent[t2] = l;
					l = specline[t];		specline[t]=specline[t2];specline[t2]=l;
				}
			}

		// step 2: resort pre-styles
		for (int t=0;t<name.GetCount();t++)
		{
			gdbinterface.SelectStyleLine(lines[specline[t]]);
			gdbinterface.SelectStyle(name[t]);
			CString strPreStyle = gdbinterface.GetStylePreStyle();
		
			if (!strPreStyle.IsEmpty())
			{
				int insertpos;
				for (insertpos=0; insertpos < name.GetCount();insertpos++)
				{
					if (name[insertpos] == strPreStyle && specline[insertpos] == specline[t])
						break;
				}
				if (insertpos < name.GetCount() && insertpos+1 != t)
				{
					CString n = name[t];	name.RemoveAt(t);
					int l = level[t];		level.RemoveAt(t);
					/*int i = */indent[t];	indent.RemoveAt(t);
					int s = specline[t];	specline.RemoveAt(t);

					if (insertpos <= t) insertpos--;
					
					name.InsertAt(insertpos,n);
					level.InsertAt(insertpos,l);
					indent.InsertAt(insertpos,indent[insertpos-1]+1);
					specline.InsertAt(insertpos,s);
					t--;
				}
			}
		}
	}

	// ESTYLE_SORT_LEVEL resort all
	if (mpc_options->ms_options.me_style_sort == ESTYLE_SORT_LEVEL)
	{
		for (int t=0;t<name.GetCount()-1;t++)
			for (int t2=t+1;t2<name.GetCount();t2++)
			{
				if (level[t]>level[t2])
				{
					CString n = name[t];	name[t] = name[t2];		name[t2] = n;
					int l = level[t];		level[t] = level[t2];	level[t2] = l;
					l = indent[t];			indent[t] = indent[t2];	indent[t2] = l;
					l = specline[t];		specline[t]=specline[t2];specline[t2]=l;
				}
			}
	}
}


void	CPrintSkillung::GetListOfSpells(
					CStringArray& base, ///< names of the base (1-3)
					CStringArray& spec, ///< names of the spec (1-3)

					IntArray& cat_spec, ///< number of base/spec which following category belongs to +1 (- for spec)
					CStringArray& cat,  ///< category

					IntArray& spell_cat, ///< number of category which following spell belongs to
					CStringArray& name,	 ///< names of all spells
					IntArray& level		 ///< level of these spells
					)
{

	// Maik Jurkait [29.12.2004]
	//===========================================
	// check options
	//===========================================
	ASSERT(mpc_options);
	if (!mpc_options->ms_options.mb_spells) return;
	bool all = mpc_options->ms_options.mb_all_spells;



	// Maik Jurkait [29.12.2004]
	//===========================================
	// Get spell lines
	//===========================================
	CStringArray lines;
	gdbinterface.GetListOfAllSpellLines(lines);

	for (int t=0;t<lines.GetCount();t+=2)
	{
		base.Add(lines[t]);
		spec.Add(lines[t+1]);
	}

	// Maik Jurkait [29.12.2004]
	//===========================================
	// Get categories
	//===========================================
	for (int t=0;t<base.GetCount();t++)
	{
		gdbinterface.SelectSpellLine(base[t]);

		CStringArray catnames;
		gdbinterface.GetListOfSpellCatsBase(catnames);

		for (int t2 = 0; t2< catnames.GetCount();t2++)
		{
			cat.Add(catnames[t2]);
			cat_spec.Add(t+1);

			gdbinterface.SelectSpellCatBase(catnames[t2]);

			CStringArray spname;
			IntArray splevels;
			gdbinterface.GetListOfSpells(&spname, &splevels);

			for (int t3=0;t3<spname.GetCount();t3++)
			{
				if (!all && splevels[t3]> (int)mpc_doc->GetLevel()) continue;

				spell_cat.Add((int)cat.GetCount()-1);
				name.Add(spname[t3]);
				level.Add(splevels[t3]);
			}
		}

		gdbinterface.GetListOfSpellCatsSpec(catnames);

		for (int t2 = 0; t2< catnames.GetCount();t2++)
		{
			cat.Add(catnames[t2]);
			cat_spec.Add(-(t+1));

			gdbinterface.SelectSpellCatSpec(catnames[t2]);

			CStringArray spname;
			IntArray splevels;
			gdbinterface.GetListOfSpells(&spname, &splevels);

			for (int t3=0;t3<spname.GetCount();t3++)
			{
				if (!all && splevels[t3]> (int)mpc_doc->GetSpecLevel(base[t])) continue;

				spell_cat.Add((int)cat.GetCount()-1);
				name.Add(spname[t3]);
				level.Add(splevels[t3]);
			}

		}
	}

	
//	for (int t=0;t<name.GetCount();t++)
//	{
//		TRACE2("(%2i) %s ->\t",level[t],name[t]);
//		TRACE1("%s:\t",cat[spell_cat[t]]);
//
//		int idx = cat_spec[spell_cat[t]];
//		if (idx>0)
//			TRACE1("%s\n",base[idx-1]);
//		else
//			TRACE2("%s (%s)\n",spec[-idx-1],base[-idx-1]);
//	}
//
//
//	TRACE("-----------------------\n");
}



void	CPrintSkillung::GetListOfRAs(CStringArray& names, CStringArray& shnames, CStringArray& reuse, CStringArray& ratypes, CStringArray& types, CStringArray lvl[5])
{

	ASSERT(mpc_options);
	if (!mpc_options->ms_options.mb_ras) return;


    IntArray a_raids;
	gdbinterface.GetListOfRANF(a_raids);

	IntArray n_ratypes;

	for (int t=0;t<names.GetCount();t++)
	{

		gdbinterface.SelectRANF( (enum_RA_id)a_raids[t]);

        names.Add( gdbinterface.GetRANFName() );
		shnames.Add(CString());
		reuse.Add(CString());
		n_ratypes.Add(0);

		int type;
        string _shname,_reuse;
		gdbinterface.GetRAInfoNF(_shname,_reuse,n_ratypes[t],type);
        shnames[t]=_shname.c_str();
        reuse[t]=_reuse.c_str();

		int level = mpc_doc->GetRRNFLevel((enum_RA_id)a_raids[t]);

		if (!mpc_options->ms_options.mb_all_ras)
		{
			if (n_ratypes[t] == 2 && mpc_doc->GetRR()<40)
			{
				names.RemoveAt(t);
				shnames.RemoveAt(t);
				reuse.RemoveAt(t);
				n_ratypes.RemoveAt(t);
				t--;
				continue;
			}

			if (level == 0 && n_ratypes[t] != 2)
			{
				names.RemoveAt(t);
				shnames.RemoveAt(t);
				reuse.RemoveAt(t);
				n_ratypes.RemoveAt(t);
				t--;
				continue;
			}
		}

		switch (n_ratypes[t])
		{
			case 0: ratypes.Add(_T("Normal")); break;
			case 1: ratypes.Add(_T("Timed")); break;
			case 2: ratypes.Add(_T("RR5")); break;
			default: ASSERT(false);
		}

		switch (type)
		{
			case 2: types.Add(_T("active")); break;
			case 1: types.Add(_T("passive")); break;
			default: ASSERT(false);
		}

		string l[9];
		gdbinterface.GetRALevelsNF(l);
        for (int rt=0;rt<9;++rt)
		    lvl[rt].Add(l[rt].c_str());

		if (n_ratypes[t] != 2 && !mpc_options->ms_options.mb_all_ras)
			for (int t2=level;t2<9;t2++)
			{
				ASSERT(t== lvl[t2].GetCount()-1);
				lvl[t2][t] = "";
			}
	}


	// sort
	for (int t1=0;t1<names.GetCount()-1;t1++)
		for (int t2=t1+1;t2<names.GetCount();t2++)
		{
			bool swap = n_ratypes[t1]>n_ratypes[t2];
			if (n_ratypes[t1] == n_ratypes[t2])
			{
				swap = names[t1]>names[t2];
			}


			if (swap)
			{
				CString temp;
				temp = names[t1]; names[t1] = names[t2]; names[t2] = temp;
				temp = shnames[t1]; shnames[t1] = shnames[t2]; shnames[t2] = temp;
				temp = reuse[t1]; reuse[t1] = reuse[t2]; reuse[t2] = temp;
				temp = ratypes[t1]; ratypes[t1] = ratypes[t2]; ratypes[t2] = temp;
				temp = types[t1]; types[t1] = types[t2]; types[t2] = temp;
                for (int t=0;t<9;++t)
                    { temp = lvl[t][t1]; lvl[t][t1] = lvl[t][t2]; lvl[t][t2] = temp; }
				int tt = n_ratypes[t1]; n_ratypes[t1] = n_ratypes[t2]; n_ratypes[t2] = tt;
			}
		}

/*
	TRACE("--------------------------\n");
	for (int t=0;t<names.GetCount();t++)
	{
		TRACE1("%s;\t",names[t]);
		TRACE1("%s;\t",shnames[t]);
		TRACE1("%s;\t",reuse[t]);
		TRACE1("%s;\t",ratypes[t]);
		TRACE1("%s;\t",types[t]);
		TRACE1("%s;\t",lvl[0][t]);
		TRACE1("%s;\t",lvl[1][t]);
		TRACE1("%s;\t",lvl[2][t]);
		TRACE1("%s;\t",lvl[3][t]);
		TRACE1("%s;\t",lvl[4][t]);

		TRACE("\n");
	}

	TRACE("--------------------------\n");
	*/
}




void CPrintSkillung::PrintInfo(CPage* pPage, CPrintRegion* Region)
{
	double Row = 0.0;
	CString temp;


	temp = CFileName(mpc_doc->GetPathName()).GetFileName();

	// Maik Jurkait [5.1.2005]
	//===========================================
	// make all first names uppercase
	//===========================================
	int pos = -1;
	do
	{
		pos++;
		if (pos >= temp.GetLength()) break;
		temp.SetAt(pos, (CString::XCHAR)towupper(temp[pos]));
	}
	while ( (pos = temp.Find(_T(' '),pos))!=-1);


	Row = PrintTab(pPage,Region,Row,0.06,1.0,_T("Name:"),temp);


	float level = mpc_doc->GetLevel();
	if (((int)level) == level )
		temp.Format(_T("%0.0f"),mpc_doc->GetLevel());
	else
		temp.Format(_T("%0.1f"),mpc_doc->GetLevel());

	CString fieldname,fieldformat;
	fieldname.LoadString(IDS_PRINT_INFO_FIELD1);
		Row =PrintTab(pPage,Region,Row,0.06,1.0,fieldname, temp);
	fieldname.LoadString(IDS_PRINT_INFO_FIELD2);
		Row =PrintTab(pPage,Region,Row,0.06,1.0,fieldname, gdbinterface.GetRealmName() );
	fieldname.LoadString(IDS_PRINT_INFO_FIELD3);
		Row =PrintTab(pPage,Region,Row,0.06,1.0,fieldname, gdbinterface.GetClassName().c_str() );
	fieldname.LoadString(IDS_PRINT_INFO_FIELD4);
	    Row =PrintTab(pPage,Region,Row,0.06,1.0,fieldname, gdbinterface.GetRaceName() );

	CTime curtime = CTime::GetCurrentTime();
	fieldname.LoadString(IDS_PRINT_INFO_FIELD5);
	fieldformat.LoadString(IDS_PRINT_INFO_FIELD5_FORMAT);
	Row = PrintTab(pPage,Region,Row+0.03,0.06,1.0,6,fieldname,curtime.Format(fieldformat));




	// Maik Jurkait [5.1.2005]
	//===========================================
	// get program version
	//===========================================
	TCHAR buffer[MAX_PATH];
	if (GetModuleFileName( 0, buffer, MAX_PATH ))
	{
		HANDLE	h_file;
		h_file = CreateFile(buffer, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,OPEN_EXISTING,0,NULL);

		DWORD size, dummy;
	    GetModuleFileName(NULL, buffer, MAX_PATH);
   		size = GetFileVersionInfoSize(buffer, &dummy);
        if (size)
		{
        		char *buf = (char *)malloc(size);
        		GetFileVersionInfo(buffer, NULL, size, buf);
        		VS_FIXEDFILEINFO *qbuf;
        		UINT len;
        		if (VerQueryValue(buf, _T("\\"), (void **)&qbuf, &len)) 
				{
					if (LOWORD(qbuf->dwFileVersionLS) == 0)
					{
						if (HIWORD(qbuf->dwFileVersionLS) == 0)
						{
							temp.Format(_T("%d.%d"), HIWORD(qbuf->dwFileVersionMS),	LOWORD(qbuf->dwFileVersionMS));
						}
						else
						temp.Format(_T("%d.%d.%d"), 
								HIWORD(qbuf->dwFileVersionMS),	LOWORD(qbuf->dwFileVersionMS), 
								HIWORD(qbuf->dwFileVersionLS));
					}
					else
					temp.Format(_T("%d.%d.%d.%d"), 
								HIWORD(qbuf->dwFileVersionMS),	LOWORD(qbuf->dwFileVersionMS), 
								HIWORD(qbuf->dwFileVersionLS),	LOWORD(qbuf->dwFileVersionLS));
	       		}
       			free(buf);
        	}
	}

	Row = PrintTab(pPage,Region,Row,0.06,1.0,6,_T("Ver:"),temp);

}






void CPrintSkillung::PrintStats(CPage* pPage, CPrintRegion* Region)
{
	int statsbase[8], stats[8];
	mpc_doc->GetStatsModif(stats);
	gdbinterface.GetStats(statsbase);

	double Row = 0.0;
	CString temp;

	temp.Format(_T("%i"),statsbase[0]+stats[0]);	Row =PrintTab(pPage,Region,Row,0.06,0.4,_T("Str:"),temp);
	temp.Format(_T("%i"),statsbase[1]+stats[1]);	Row =PrintTab(pPage,Region,Row,0.06,0.4,_T("Con:"),temp);
	temp.Format(_T("%i"),statsbase[2]+stats[2]);	Row =PrintTab(pPage,Region,Row,0.06,0.4,_T("Dex:"),temp);
	temp.Format(_T("%i"),statsbase[3]+stats[3]);	Row =PrintTab(pPage,Region,Row,0.06,0.4,_T("Qui:"),temp);
	Row = 0.0;
	temp.Format(_T("%i"),statsbase[4]+stats[4]);	Row =PrintTab(pPage,Region,Row,0.86,1.2,_T("Int:"),temp);
	temp.Format(_T("%i"),statsbase[5]+stats[5]);	Row =PrintTab(pPage,Region,Row,0.86,1.2,_T("Pie:"),temp);
	temp.Format(_T("%i"),statsbase[6]+stats[6]);	Row =PrintTab(pPage,Region,Row,0.86,1.2,_T("Emp:"),temp);
	temp.Format(_T("%i"),statsbase[7]+stats[7]);	Row =PrintTab(pPage,Region,Row,0.86,1.2,_T("Cha:"),temp);

	pPage->Line(Region,Row,0.0,Row,8.0);
	temp.Format(_T("R %i L %i (%s rps)"),(int)(mpc_doc->GetRR()/10)+1,mpc_doc->GetRR()%10, mpc_doc->FormatRps(mpc_doc->GetRR()));
	Row =pPage->Print(Region,Row+0.05,0.0,TEXT_CENTER,8,temp);

	Row =pPage->Print(Region,Row,0.0,TEXT_CENTER,9,mpc_doc->GetRRName(mpc_doc->GetRR(),gdbinterface.GetRealmID(gdbinterface.GetRealmName())));
}




void	CPrintSkillung::PrintML(CPage* pPage, CPrintRegion* Region)
{
	double Row = 0.0;
	CString temp;

	CString mpath = gdbinterface.GetMasterTrack(mpc_doc->GetMasterPath());

	double rowstart = pPage->Print(Region,0.0,0.0,TEXT_BOLD|TEXT_CENTER|TEXT_NORMAL|TEXT_SINGLELINE,9,mpath);

	CStringArray results;
	gdbinterface.SelectMasterTrack(mpath);
	gdbinterface.GetMasterLevels(results);
	Row = rowstart;
	double Col = 0.03;
	for (int t=0;t<results.GetCount();t++)
	{
		if (t== results.GetCount()/2) { Row = rowstart; Col = 1.5; }
		UINT size = TEXT_NORMAL | TEXT_ITALIC;
		if (t < mpc_doc->GetMasterLevel()) size = TEXT_NORMAL;
		Row = pPage->Print(Region,Row,Col,size|TEXT_SINGLELINE,9,results[t]);
	}
}










CPrintSkillung::struct_page_contents::struct_page_contents()
{
	b_title = false;
	b_base_stats = false;
	n_base_end = 0;
	b_skills = false;
	n_skills_end = 0;

	idx_style_start = -1;
	idx_style_end = -1;
	n_styles_end = 0;
	n_style_nof_heads = 0; 
	b_styles_print_head = true;

	idx_spell_start = -1;
	idx_spell_end = -1;
	n_spell_end = 0;
	n_spell_nof_heads = 0;
	b_spells_print_description = false;

	idx_ra_start = -1;
	idx_ra_end  = -1;
	n_ra_nof_heads = 0;
}



void	CPrintSkillung::NewPage()
{
	struct_page_contents s; 

	ASSERT(mpc_options);
	// no style header for some sort-types
    if (mpc_options->ms_options.me_style_sort == ESTYLE_SORT_LEVEL ||
		mpc_options->ms_options.me_style_sort == ESTYLE_SORT_PERQUISITE)
		s.b_styles_print_head = false;

	m_as_pages.Add(s);
}


#define CURPAGE m_as_pages[m_as_pages.GetCount()-1]



BOOL CPrintSkillung::OnPreparePrinting(CPrintInfo* pInfo)
{
	// Maik Jurkait [29.12.2004]
	//===========================================
	// Let the user choose what to print
	//===========================================
	if (!mpc_options)
	{
		mpc_options = new CDialogPrinterOptions(mpc_doc);
		if (mpc_options->DoModal() != IDOK) return FALSE;
	}


	BOOL res = CPrintBase::OnPreparePrinting(pInfo);
	if (!res) return FALSE;


	// calculate pages
	m_as_pages.RemoveAll();


	// Maik Jurkait [28.12.2004]
	//===========================================
	// create a dummy page for calculation
	//===========================================
	CDC dc;
	PRINTDLG prtdlg;
	if (!AfxGetApp()->GetPrinterDeviceDefaults(&prtdlg))
	{
		AfxMessageBox(IDS_ERROR_NO_PRINTER);
		return FALSE;
	};
	VERIFY(AfxGetApp()->CreatePrinterDC(dc));
    
	pInfo->m_rectDraw.SetRect(0, 0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)) ;

	CPage* pPage= new CPage(pInfo->m_rectDraw,&dc,MM_TEXT);





	NewPage();
	// Maik Jurkait [28.12.2004]
	//===========================================
	// PAGE 1
	//===========================================
	CURPAGE.b_title = true;
	CURPAGE.b_base_stats = true;
	CURPAGE.n_base_end = 1.7;
	CURPAGE.b_skills = true;


	// Maik Jurkait [28.12.2004]
	//===========================================
	// Calc size of skills
	//===========================================
 	CStringArray names;
	CArray <int> skills;
	GetAllSkillNames(names);

	double Row = CURPAGE.n_base_end;
	if (mpc_doc->IsCarrerMode())
	{
		for (int steps = 0;steps<3;steps++)
		{
			Row = pPage->Print(Row,1.50+0.3,TEXT_BOLD|TEXT_SINGLELINE,9,CString("20"));
			for (int t=0;t<names.GetCount();t++)
				if (GetSkillLevel(names[t],50.0f)>1) 
					Row = pPage->Print(Row,0.1,TEXT_BOLD|TEXT_SINGLELINE,9,names[t]);
			Row = Row + 0.2;
		}

	}
	else
	{
		for (int t=0;t<names.GetCount();t++)
			Row = PrintTab(pPage,NULL,Row,0.5,1.5,names[t],CString("20"));
	}

	CURPAGE.n_skills_end = Row + 0.4;




	// Maik Jurkait [25.9.2004]
	//===========================================
	// Style
	//===========================================
	{

		CStringArray lines;
		CStringArray names;
		IntArray	 levels;
		IntArray	 nspecline;
		IntArray	 indent;
		int			 nof_specs;

		GetListOfStyles(lines, nspecline, indent, names, levels,nof_specs);

		if (names.GetCount()==0)
		{
			CURPAGE.n_styles_end = CURPAGE.n_skills_end;
		}
		else
		{
			int current = 0;

			while (current < names.GetCount())
			{
				//create and use a table
				TABLEHEADER* pTable = new TABLEHEADER;
				pTable->PointSize = 8;
				pTable->LineSize = 1;

				//default shown only for demo purposes
				pTable->UseInches  = TRUE;
				pTable->AutoSize   = FALSE;
				pTable->Border     = FALSE;
				pTable->FillFlag   = FILL_NONE;
				pTable->NumColumns = 1;
				pTable->NumRows    = (int)names.GetCount();
				pTable->StartRow   = CURPAGE.n_skills_end;
				pTable->StartCol   = 0.0;
				pTable->EndCol     = 1.0;
				pTable->ColDesc[0].Init(1.0,"Name");
				pPage->Table(pTable);

				int lines_on_that_page = min((int)names.GetCount()-current , pPage->GetMaxLines(pTable));

				// Maik Jurkait [29.12.2004]
				//===========================================
				// now check for header-lines (style-line changes)
				//===========================================
				if (CURPAGE.b_styles_print_head)
				{
					CURPAGE.n_style_nof_heads = 1;
					for (int sl = current+1; sl < current+lines_on_that_page;sl++)
						if (nspecline[sl] != nspecline[sl-1])
						{ 
							if (lines_on_that_page < (int)names.GetCount()-current)
										lines_on_that_page--;

							CURPAGE.n_style_nof_heads++;
						}

					if (lines_on_that_page < (int)names.GetCount()-current)
					{
						// and if last line is a single style of that styleline -> break it to the next page
						if (lines_on_that_page>0 && nspecline[current+lines_on_that_page-2] != nspecline[current+lines_on_that_page-1]) 
								lines_on_that_page--;
					}
				}




				// Maik Jurkait [29.12.2004]
				//===========================================
				// insert calculations
				//===========================================
				pTable->NumRows = lines_on_that_page+CURPAGE.n_style_nof_heads;
				CURPAGE.idx_style_start = current;
				CURPAGE.idx_style_end = current+lines_on_that_page;
				CURPAGE.n_styles_end = pPage->GetEndPos(pTable);
				current+=lines_on_that_page;

				if (current < names.GetCount())
				{
					NewPage();
					CURPAGE.b_title = true;
					CURPAGE.n_skills_end = 0.5;
				}
				delete pTable;
			}

			CURPAGE.n_styles_end += 0.2;
		}
	}


	// Maik Jurkait [29.12.2004]
	//===========================================
	// Spells
	//===========================================
	{
		CStringArray	base;
		CStringArray	spec;
		IntArray		cat_spec;
		CStringArray	cat;
		IntArray		spell_cat;
		CStringArray	names;
		IntArray		levels;

		GetListOfSpells(base, spec, cat_spec, cat,  spell_cat, names, levels);


		if (names.GetCount()==0)
		{
			CURPAGE.n_spell_end = CURPAGE.n_styles_end;
		}
		else
		{
			int current = 0;

			while (current < names.GetCount())
			{
				//create and use a table
				TABLEHEADER* pTable = new TABLEHEADER;
				pTable->PointSize = 8;
				pTable->LineSize = 1;

				//default shown only for demo purposes
				pTable->UseInches  = TRUE;
				pTable->AutoSize   = FALSE;
				pTable->Border     = FALSE;
				pTable->FillFlag   = FILL_NONE;
				pTable->NumColumns = 1;
				pTable->NumRows    = (int)names.GetCount();
				pTable->StartRow   = CURPAGE.n_styles_end;
				pTable->StartCol   = 0.0;
				pTable->EndCol     = 1.0;
				pTable->ColDesc[0].Init(1.0,"Name");
				pPage->Table(pTable);

				int max_lines = pPage->GetMaxLines(pTable);
				int lines_on_that_page = min((int)names.GetCount()-current, max_lines);

				// Maik Jurkait [29.12.2004]
				//===========================================
				// calculate headers
				//===========================================
				CURPAGE.n_spell_nof_heads = 0;

				int current_cat = -1;
				int current_line = -1;
				for (int sl = current; sl < current+lines_on_that_page;sl++)
				{
					// for every spellline switch we need one head
					// for every spellcat switch we need one head (or 2 if incl.desc)
					int neededheads = 0;
					int idx = cat_spec[spell_cat[sl]];
					if (current_line != idx)			neededheads++;
					if (current_cat != spell_cat[sl])
					{
						neededheads++;
						if (mpc_options->ms_options.mb_spell_description)	neededheads++;
					}

					// we have header-lines
					if (neededheads>0)
					{
						if (lines_on_that_page+CURPAGE.n_spell_nof_heads+ neededheads > max_lines)	
						{
							// check if headers of next spell will exceed page size
							if (sl+neededheads >= current+lines_on_that_page)
							{
								// do calculation again without last spell
								lines_on_that_page--;
								sl--;
								continue;
							}

							lines_on_that_page-=neededheads;
						}

						CURPAGE.n_spell_nof_heads += neededheads; 
						current_line = idx;
						current_cat = spell_cat[sl];

					}

				}


				// Maik Jurkait [30.12.2004]
				//===========================================
				// set page settings
				//===========================================
				if (lines_on_that_page>0)
				{
					pTable->NumRows = lines_on_that_page+CURPAGE.n_spell_nof_heads;
					CURPAGE.idx_spell_start = current;
					CURPAGE.idx_spell_end = current+lines_on_that_page;
					CURPAGE.n_spell_end = pPage->GetEndPos(pTable);
					current+=lines_on_that_page;
				}

				if (current < names.GetCount())
				{
					NewPage();
					CURPAGE.b_title = true;
					CURPAGE.n_styles_end = 0.5;
				}
				delete pTable;
			}

			CURPAGE.n_spell_end += 0.2;
		}
	}



	// Maik Jurkait [5.1.2005]
	//===========================================
	// RA's
	//===========================================
	{
		CStringArray names;
		CStringArray shnames;
		CStringArray reuse;
		CStringArray ratypes;
		CStringArray types;
		CStringArray lvl[5];
		GetListOfRAs(names, shnames, reuse, ratypes, types, lvl);


		if (names.GetCount()==0)
		{
			CURPAGE.n_ra_end = CURPAGE.n_spell_end;
		}
		else
		{
			int current = 0;

			while (current < names.GetCount())
			{
				//create and use a table
				TABLEHEADER* pTable = new TABLEHEADER;
				pTable->PointSize = 8;
				pTable->LineSize = 1;

				//default shown only for demo purposes
				pTable->UseInches  = TRUE;
				pTable->AutoSize   = FALSE;
				pTable->Border     = FALSE;
				pTable->FillFlag   = FILL_NONE;
				pTable->NumColumns = 1;
				pTable->NumRows    = (int)names.GetCount();
				pTable->StartRow   = CURPAGE.n_spell_end;
				pTable->StartCol   = 0.0;
				pTable->EndCol     = 1.0;
				pTable->ColDesc[0].Init(1.0,"Name");
				pPage->Table(pTable);

				int lines_on_that_page = min((int)names.GetCount()-current , pPage->GetMaxLines(pTable));


				// Maik Jurkait
				//===========================================
				// now check for header-lines (ra-type changes)
				//===========================================
				CURPAGE.n_ra_nof_heads = 1;
				for (int sl = current+1; sl < current+lines_on_that_page;sl++)
					if (ratypes[sl] != ratypes[sl-1])
					{ 
						if (lines_on_that_page < (int)names.GetCount()-current)
									lines_on_that_page--;
						CURPAGE.n_ra_nof_heads++;
					}

				if (lines_on_that_page < (int)names.GetCount()-current)
				{
					// and if last line is a single style of that styleline -> break it to the next page
					if (lines_on_that_page>1 && types[current+lines_on_that_page-2] != types[current+lines_on_that_page-1]) 
							lines_on_that_page--;
				}


				// Maik Jurkait [30.12.2004]
				//===========================================
				// set page settings
				//===========================================
				if (lines_on_that_page>0)
				{
					pTable->NumRows = lines_on_that_page+CURPAGE.n_ra_nof_heads;
					CURPAGE.idx_ra_start = current;
					CURPAGE.idx_ra_end = current+lines_on_that_page;
					CURPAGE.n_ra_end = pPage->GetEndPos(pTable);
					current+=lines_on_that_page;
				}

				if (current < names.GetCount())
				{
					NewPage();
					CURPAGE.b_title = true;
					CURPAGE.n_spell_end = 0.5;
				}
				delete pTable;
			}

			CURPAGE.n_ra_end += 0.2;
		}
	}


	#ifdef _DEBUG
		for (int t=0;t<m_as_pages.GetCount();t++)		
		{
			TRACE1("Page: %i\n",t+1);
			if (m_as_pages[t].b_title)		TRACE(_T("Title\n"));
			if (m_as_pages[t].b_base_stats)	TRACE1("Stats - Endline = %lg\n",	m_as_pages[t].n_base_end);
			if (m_as_pages[t].b_skills)		TRACE1("Skills - Endline = %lg\n",	m_as_pages[t].n_skills_end);

			if (m_as_pages[t].idx_style_start!=-1)	
			{
				TRACE2("Styles (%i - %i) ",m_as_pages[t].idx_style_start,m_as_pages[t].idx_style_end);
				TRACE2(" Heads: %i  - Endline = %lg\n",m_as_pages[t].n_style_nof_heads,m_as_pages[t].n_styles_end);

			}

			if (m_as_pages[t].idx_spell_start!=-1)	
			{
				TRACE2("Spells (%i - %i) ",m_as_pages[t].idx_spell_start,m_as_pages[t].idx_spell_end);
				TRACE2(" Heads: %i  - Endline = %lg\n",m_as_pages[t].n_spell_nof_heads,m_as_pages[t].n_spell_end);

			}

			if (m_as_pages[t].idx_ra_start!=-1)	
			{
				TRACE2("RA's (%i - %i) ",m_as_pages[t].idx_ra_start,m_as_pages[t].idx_ra_end);
				TRACE2(" Heads: %i  - Endline = %lg\n",m_as_pages[t].n_ra_nof_heads,m_as_pages[t].n_ra_end);

			}

			TRACE(_T("\n"));
		}
	#endif



	delete pPage;
	dc.DeleteDC();

	pInfo->SetMaxPage((int)m_as_pages.GetCount());

	return TRUE;
}




#define PPAGE m_as_pages[pInfo->m_nCurPage-1]

void CPrintSkillung::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	
	double Row;
	CString temp;
	CPage* pPage= new CPage(pInfo->m_rectDraw,pDC,MM_TEXT);


	// Maik Jurkait [28.12.2004]
	//===========================================
	// Print title
	//===========================================
	if (PPAGE.b_title)
	{
		temp.LoadString(IDS_PRINT_PAGE_TITLE);
		pPage->Print(0.1,0.0,TEXT_BOLD|TEXT_CENTER,16,temp);

		if (m_as_pages.GetCount()>1)
		{
			temp.LoadString(IDS_PRINT_PAGE_FORMAT);
			pPage->Print(0.2,6.5,TEXT_RIGHT,8,temp,pInfo->m_nCurPage,m_as_pages.GetCount());
		}
	}


	// Maik Jurkait [28.12.2004]
	//===========================================
	// Base information
	//===========================================
	if (PPAGE.b_base_stats)
	{

		// Maik Jurkait [25.9.2004]
		//===========================================
		// Base information
		//===========================================
		{
			CPrintRegion *Region1=pPage->CreateRegion(0.5,0.1,PPAGE.n_base_end,2.5);
			Region1->DrawBorder();
			Region1->DrawTitle("Charakter",8,TEXT_BOLD|TEXT_CENTER|TEXT_RECT,FILL_LTGRAY);
			pPage->SetLineSpacing(1.0);
		
			PrintInfo(pPage, Region1);
		}
			

		// Maik Jurkait [25.9.2004]
		//===========================================
		// Base Stats
		//===========================================
		{
			CPrintRegion *Region2=pPage->CreateRegion(0.5,2.7,PPAGE.n_base_end,4.5);
			Region2->DrawBorder();
			Region2->DrawTitle("Basis-Stats",8,TEXT_BOLD|TEXT_CENTER|TEXT_RECT,FILL_LTGRAY);
			pPage->SetLineSpacing(1.0);

			PrintStats( pPage, Region2);
		}



		// Maik Jurkait [25.9.2004]
		//===========================================
		// Master Level
		//===========================================
		{
			CPrintRegion *Region3=pPage->CreateRegion(0.5,4.7,PPAGE.n_base_end,7.9);
			if (Region3)
			{
				Region3->DrawBorder();
				Region3->DrawTitle("Master-Level",8,TEXT_BOLD|TEXT_CENTER|TEXT_RECT,FILL_LTGRAY);
				pPage->SetLineSpacing(1.0);

				if (mpc_doc->GetMasterLevel()>0)
						PrintML( pPage, Region3);
			}
		}
	}


	// Maik Jurkait [25.9.2004]
	//===========================================
	// Skill
	//===========================================
	if (PPAGE.b_skills)
	{
 		CStringArray names;
		CArray <int> skills;
		GetAllSkillNames(names);

		if (mpc_doc->IsCarrerMode())
		{
			Row = PPAGE.n_base_end + 0.2f;
			double row2 = Row;

			for (int steps = 0;steps<3;steps++)
			{
				for (int level=steps*20;level<((steps+1)*20);level++)
				{
					if ( (int)IDX2LVL(level+1) == IDX2LVL(level+1))	
						temp.Format(_T("%0.0f"),IDX2LVL(level+1));
					else	
						temp.Format(_T("%0.1f"),IDX2LVL(level+1));

					row2 = pPage->Print(Row,1.50+0.3*(level-steps*20),TEXT_BOLD|TEXT_SINGLELINE,9,temp);
				}

				for (int level=steps*20;level<((steps+1)*20);level++)
				{
					Row = row2;
					double rt = row2;
					for (int t=0;t<names.GetCount();t++)
					{
						if (GetSkillLevel(names[t],50.0f)==1) continue;

						if (level==steps*20) rt = pPage->Print(rt,0.1,TEXT_BOLD|TEXT_SINGLELINE,9,names[t]);

						if (level <5) 	continue;

						temp.Format(_T("%i"),GetSkillLevel(names[t],IDX2LVL(level+1)));
						Row = pPage->Print(Row,1.50+0.3*(level-steps*20),TEXT_NORMAL|TEXT_SINGLELINE,9,temp);
					}
				}

				Row = Row + 0.2;
			}

		}
		else
		{
			Row = PPAGE.n_base_end + 0.2f;
			for (int t=0;t<names.GetCount();t++)
			{
				temp.Format(_T("%i"),GetSkillLevel(names[t],mpc_doc->GetLevel()));
				Row = PrintTab(pPage,NULL,Row,0.5,1.5,names[t],temp);
			}
		}
	}







	// Maik Jurkait [25.9.2004]
	//===========================================
	// Style
	//===========================================
	if (PPAGE.idx_style_start != -1)
	{

		CStringArray lines;
		CStringArray names;
		IntArray	 levels;
		IntArray	 nspecline;
		IntArray	 indent;
		int			 nof_specs;

		GetListOfStyles(lines, nspecline, indent, names, levels,nof_specs);

		//create and use a table
		TABLEHEADER* pTable = new TABLEHEADER;
		int tabpts = 8;
		pTable->PointSize = tabpts;
		pTable->LineSize = 1;

		//default shown only for demo purposes
		pTable->UseInches  = TRUE;
		pTable->AutoSize   = FALSE;
		pTable->Border     = FALSE;
		pTable->FillFlag   = FILL_NONE;
		pTable->NumColumns = 8;
		pTable->NumRows    = PPAGE.n_style_nof_heads+PPAGE.idx_style_end-PPAGE.idx_style_start;
		pTable->StartRow   = PPAGE.n_skills_end;
//		pTable->StartCol   = 1.0;
//		pTable->EndCol     = 8.0;
		pTable->StartCol   = 0.5;
		pTable->EndCol     = 7.5;

		pTable->ColDesc[0].Init(1.2,"Name",FILL_NONE);
		pTable->ColDesc[1].Init(0.3,"Level",FILL_NONE /*FILL_LTGRAY*/);
		pTable->ColDesc[2].Init(1.0,"Pre"); 
		pTable->ColDesc[3].Init(0.8,"Attack"); 
		pTable->ColDesc[4].Init(1.0,"Defense"); 
		pTable->ColDesc[5].Init(0.8,"Fatigue"); 
		pTable->ColDesc[6].Init(0.8,"Damage"); 
		pTable->ColDesc[7].Init(1.1,"Effect"); 
//								7.0

		pPage->Table(pTable);

		int headers = PPAGE.n_style_nof_heads;
		int row = 0;
		int current_styleline = -1;
		for (int current = PPAGE.idx_style_start;current < PPAGE.idx_style_end; current++)
		{
			gdbinterface.SelectStyleLine(lines[nspecline[current]]);
			gdbinterface.SelectStyle(names[current]);
			CStringArray name,value;
			gdbinterface.GetStyleDescription(name,value);

			// insert sub-header
			if (PPAGE.b_styles_print_head && nspecline[current] != current_styleline)
			{
				TABLEHEADER savestate(*pTable);
				pTable->NumColumns = 1;
				pTable->ColDesc[0].Width = pTable->EndCol - pTable->StartCol;
				pTable->ColDesc[0].FillFlag = FILL_LTGRAY;

				pPage->Print(pTable,row,0,tabpts,TEXT_LEFT|TEXT_BOLD|TEXT_RECT,"%s",lines[nspecline[current]]);

				*pTable = savestate;

				current_styleline = nspecline[current];
				row++;
				headers--;
			}



			//place information in a table 
			CString strident(' ',indent[current]*3);
			pPage->Print(pTable,row,0,tabpts,TEXT_LEFT/*|TEXT_BOLD*/,"%s%s",strident,names[current]);
			pPage->Print(pTable,row,1,tabpts,TEXT_CENTER,"%i",levels[current]);

			for (int t=2;t<value.GetCount()&&t<8;t++)
				pPage->Print(pTable,row,t,tabpts,TEXT_CENTER,"%s",value[t]);

			row++;
		}
		ASSERT(headers == 0);
		delete pTable;
	}



	// Maik Jurkait [25.9.2004]
	//===========================================
	// Spells
	//===========================================
	if (PPAGE.idx_spell_start != -1)
	{
		CStringArray	base;
		CStringArray	spec;
		IntArray		cat_spec;
		CStringArray	cat;
		IntArray		spell_cat;
		CStringArray	names;
		IntArray		levels;

		GetListOfSpells(base, spec, cat_spec, cat,  spell_cat, names, levels);


		//create and use a table
		TABLEHEADER* pTable = new TABLEHEADER;
		pTable->PointSize = 8;
		pTable->LineSize = 1;

		//default shown only for demo purposes
		pTable->UseInches  = TRUE;
		pTable->AutoSize   = FALSE;
		pTable->Border     = FALSE;
		pTable->FillFlag   = FILL_NONE;
		pTable->NumColumns = 7;
		pTable->NumRows    = PPAGE.n_spell_nof_heads+PPAGE.idx_spell_end-PPAGE.idx_spell_start;
		pTable->StartRow   = PPAGE.n_styles_end;
		pTable->StartCol   = 0.2;
		pTable->EndCol     = 8.0;

		pTable->StartCol   = 0.5;
		pTable->EndCol     = 7.5;

		pTable->ColDesc[0].Init(1.5,"Name",FILL_NONE);
		pTable->ColDesc[1].Init(0.3,"Level",FILL_NONE /*FILL_LTGRAY*/);
//		pTable->ColDesc[2].Init(1.0,"Target"); 
//		pTable->ColDesc[3].Init(1.0,"C/D/R"); 
//		pTable->ColDesc[4].Init(1.0,"Range/Radius"); 
//		pTable->ColDesc[5].Init(1.0,"Cost"); 
//		pTable->ColDesc[6].Init(2.0,"Effect"); 
		pTable->ColDesc[2].Init(0.7,"Target"); 
		pTable->ColDesc[3].Init(1.0,"C/D/R"); 
		pTable->ColDesc[4].Init(1.0,"Range/Radius"); 
		pTable->ColDesc[5].Init(0.6,"Cost"); 
		pTable->ColDesc[6].Init(1.9,"Effect"); 

		pPage->Table(pTable);

		int row = 0;
		int current_cat = -1;
		int current_line = -1;
		int headers = PPAGE.n_spell_nof_heads;
		for (int current = PPAGE.idx_spell_start;current < PPAGE.idx_spell_end; current++)
		{
			int idx = cat_spec[spell_cat[current]];
			gdbinterface.SelectSpellLine(base[abs(idx)-1]);
			if (idx >0)
				gdbinterface.SelectSpellCatBase(cat[spell_cat[current]]);
			else
				gdbinterface.SelectSpellCatSpec(cat[spell_cat[current]]);

			gdbinterface.SelectSpell(names[current],levels[current]);

			CStringArray key;
			CStringArray value;
			gdbinterface.GetSpellDescription(key,value);

			// spell line head
			if (current_line != idx)
			{
				TABLEHEADER savestate(*pTable);
				pTable->NumColumns = 1;
				pTable->ColDesc[0].Width = pTable->EndCol - pTable->StartCol;
				pTable->ColDesc[0].FillFlag = FILL_LTGRAY;

				if (idx >0)
					pPage->Print(pTable,row,0,8,TEXT_LEFT|TEXT_BOLD|TEXT_RECT,"%s",base[idx-1]);
				else
				{
					if (spec[-idx-1].IsEmpty())
						pPage->Print(pTable,row,0,8,TEXT_LEFT|TEXT_BOLD|TEXT_RECT,"%s",base[-idx-1]);
					else
						pPage->Print(pTable,row,0,8,TEXT_LEFT|TEXT_BOLD|TEXT_RECT,"%s",spec[-idx-1]);
				}


				*pTable = savestate;

				current_line = idx;
				row++;
				headers--;
			}


			// spell cat head
			if (current_cat != spell_cat[current])
			{
				TABLEHEADER savestate(*pTable);
				pTable->NumColumns = 1;
				pTable->ColDesc[0].Width = pTable->EndCol - pTable->StartCol;

				pPage->Print(pTable,row,0,8,TEXT_LEFT|TEXT_BOLD,"    %s",cat[spell_cat[current]]);
				current_cat = spell_cat[current];

				*pTable = savestate;
				row++;
				headers--;

				if (mpc_options->ms_options.mb_spell_description)
				{
					TABLEHEADER savestate(*pTable);

					pTable->NumColumns = 1;
					pTable->ColDesc[0].Width = pTable->EndCol - pTable->StartCol;

					pPage->Print(pTable,row,0,6,TEXT_LEFT|TEXT_ITALIC|TEXT_RECT,"    %s",gdbinterface.GetSpellDescriptionText());

					*pTable = savestate;

					row++;
					headers--;
				}
			}


			//place information in a table 
			pPage->Print(pTable,row,0,8,TEXT_LEFT,"%s",names[current]);
			pPage->Print(pTable,row,1,8,TEXT_CENTER,"%i",levels[current]);
			pPage->Print(pTable,row,2,8,TEXT_CENTER,"%s",value[2]);
			pPage->Print(pTable,row,3,8,TEXT_CENTER,"%s",value[3]);
			pPage->Print(pTable,row,4,8,TEXT_CENTER,"%s",value[4]);
			pPage->Print(pTable,row,5,8,TEXT_CENTER,"%s",value[5]);
			pPage->Print(pTable,row,6,8,TEXT_CENTER,"%s",value[6]);
			row++;
		}
		delete pTable;
		ASSERT(headers == 0);
	}




	// Maik Jurkait [5.1.2005]
	//===========================================
	// RA's
	//===========================================
	if (PPAGE.idx_ra_start != -1)
	{
		CStringArray names;
		CStringArray shnames;
		CStringArray reuse;
		CStringArray ratypes;
		CStringArray types;
		CStringArray lvl[5];
		GetListOfRAs(names, shnames, reuse, ratypes, types, lvl);


		//create and use a table
		TABLEHEADER* pTable = new TABLEHEADER;
		int tabpts = 8;
		pTable->PointSize = tabpts;
		pTable->LineSize = 1;

		//default shown only for demo purposes
		pTable->UseInches  = TRUE;
		pTable->AutoSize   = FALSE;
		pTable->Border     = FALSE;
		pTable->FillFlag   = FILL_NONE;
		pTable->NumColumns = 9;
		pTable->NumRows    = PPAGE.n_ra_nof_heads+PPAGE.idx_ra_end-PPAGE.idx_ra_start;
		pTable->StartRow   = PPAGE.n_spell_end;
		pTable->StartCol   = 0.9;
		pTable->EndCol     = 8.0;

		pTable->StartCol   = 0.5;
		pTable->EndCol     = 7.5;

		pTable->ColDesc[0].Init(1.5,"Name",FILL_NONE);
		pTable->ColDesc[1].Init(0.6,"abkz",FILL_NONE /*FILL_LTGRAY*/);
		pTable->ColDesc[2].Init(0.45,"Art"); 
		pTable->ColDesc[3].Init(0.55,"Reuse"); 
		pTable->ColDesc[4].Init(0.8,"Level 1"); 
		pTable->ColDesc[5].Init(0.8,"Level 2"); 
		pTable->ColDesc[6].Init(0.8,"Level 3"); 
		pTable->ColDesc[7].Init(0.8,"Level 4"); 
		pTable->ColDesc[8].Init(0.7,"Level 5"); 
//								7

		pPage->Table(pTable);

		int headers = PPAGE.n_ra_nof_heads;
		int row = 0;
		CString current_ratype = _T("");
		for (int current = PPAGE.idx_ra_start;current < PPAGE.idx_ra_end; current++)
		{
			// insert sub-header
			if (ratypes[current] != current_ratype)
			{
				TABLEHEADER savestate(*pTable);
				pTable->NumColumns = 1;
				pTable->ColDesc[0].Width = pTable->EndCol - pTable->StartCol;
				pTable->ColDesc[0].FillFlag = FILL_LTGRAY;

				pPage->Print(pTable,row,0,tabpts,TEXT_LEFT|TEXT_BOLD|TEXT_RECT,"%s",ratypes[current]);

				*pTable = savestate;

				current_ratype = ratypes[current];
				row++;
				headers--;
			}


			//place information in a table 
			pPage->Print(pTable,row,0,tabpts,TEXT_LEFT,"%s",names[current]);
			pPage->Print(pTable,row,1,tabpts,TEXT_CENTER,"%s",shnames[current]);
			pPage->Print(pTable,row,2,tabpts,TEXT_CENTER,"%s",types[current]);
			pPage->Print(pTable,row,3,tabpts,TEXT_CENTER,"%s",reuse[current]);
			pPage->Print(pTable,row,4,tabpts,TEXT_CENTER,"%s",lvl[0][current]);
			pPage->Print(pTable,row,5,tabpts,TEXT_CENTER,"%s",lvl[1][current]);
			pPage->Print(pTable,row,6,tabpts,TEXT_CENTER,"%s",lvl[2][current]);
			pPage->Print(pTable,row,7,tabpts,TEXT_CENTER,"%s",lvl[3][current]);
			pPage->Print(pTable,row,8,tabpts,TEXT_CENTER,"%s",lvl[4][current]);
			row++;
		}
		ASSERT(headers == 0);
		delete pTable;
	}


	delete pPage; 
}



void CPrintSkillung::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	UNREFERENCED_PARAMETER(pDC);
	UNREFERENCED_PARAMETER(pInfo);
}

void CPrintSkillung::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{
	UNREFERENCED_PARAMETER(pDC);
	UNREFERENCED_PARAMETER(pInfo);
	UNREFERENCED_PARAMETER(point);
	UNREFERENCED_PARAMETER(pView);
}

void CPrintSkillung::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	UNREFERENCED_PARAMETER(pDC);
	UNREFERENCED_PARAMETER(pInfo);
}



